#include <iostream>
#include <cmath>
using namespace std;

/*
 * 时钟类
 */
class Clock
{
    private:
    int Hour, Minute, Second;
    public:
    Clock(int h=0, int m=0, int s=0);
    void ShowTime();
    Clock& operator ++();
    Clock operator ++(int);
};

Clock::Clock(int h, int m, int s)
{
    if(h>=0 && h<24 && m>=0 && m<60 && s>=0 && s<60)
    {
        Hour = h;
        Minute = m;
        Second = s;
    }
    else
        cout << "输入的时间格式错误！" << endl;
}

void Clock::ShowTime()
{
    cout << Hour <<":"<<Minute<<":"<<Second<<endl;
}

/*
* 时间递增一秒（重载前缀++运算符）
*/
Clock& Clock::operator ++()
{
    Second++;
    if(Second >= 60)
    {
        Second = Second - 60;
        Minute++;
        if(Minute >= 60)
        {
            Minute = Minute - 60;
            Hour++;
            Hour = Hour%24;
        }
    }
    return *this;
}

/*
* 时间递增一秒（重载后缀++运算符）
*/
Clock Clock::operator ++(int)
{
    Clock old = *this;
    ++(*this);
    return old;
}

int main()
{
    Clock myClock(23,59,59);
    cout << "初始化显示时间为：\t\t";
    myClock.ShowTime();
    cout << "执行myClock++之后的时间为：\t";
    (myClock++).ShowTime();
    cout << "执行++myClock之后的时间为：\t";
    (++myClock).ShowTime();
    return 0;
}
